﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AdvancedCSharp
{
    public class DelegateEvents
    {
        public delegate void PriceChangedEventHandler(decimal oldPrice, decimal newPrice);
        public event PriceChangedEventHandler PriceChanged;
    }

    public class Stock
    {
        public delegate void PriceChangedEventHandler(decimal oldPrice, decimal newPrice);

        string symbol;
         decimal price;

        public Stock(string symbol)
        {
            this.symbol = symbol;
        }

        public event PriceChangedEventHandler PriceChanged;

        public decimal Price
        {
            get { return this.price; }
            set 
            {
                if (price==value)
                {
                    return;
                }
                decimal oldPrice = price;
                price = value;
                if (PriceChanged!=null)
                {
                    PriceChanged(oldPrice, price);
                }
            }
        }
    }
}
